<!-- <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>收银程序</title>
</head>
<body>
<script>
    
 
    //输入商品的单价和数量
    var price = prompt("请输入单价");
    var count = prompt("请输入数量");
 
    //计算总价
    var sumPrice = price * count;
 
    //判断是否打折
    if (sumPrice >= 500){
        sumPrice *= 0.8;
    }
 
    //给用户说需要付多少钱
    var money = prompt("您本次消费"+sumPrice+"元，请付款(输入付钱的面额即可，稍等给您找零)");
 
    // 判断用户缴费是否足够，并找零
    if (money > sumPrice) {
        // 计算找零
        var reduceMoney = money - sumPrice;
        alert("找零" + reduceMoney + "元，请收好")
    }else{
        alert("钱不够！！！！")
         //此时可以重新递归调用，代码省略
    }
 
    alert("欢迎下次光临");
    
</script>
</body>
</html> -->


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点名器</title>
    <style>
        body{
            background-color: #0D1635;
        }
        h2{
            font-size: 70px;
            color: yellow;
            text-align: center;
        }
        p{
            font-size: 60px;
            color: #fff;
            text-align: center;
        }
    </style>
</head>
<body>
    <h2 id="btn">start</h2>
    <p id="con">开始点名</p>
    <script>
        var oBtn = document.getElementById("btn");
        var oCon = document.getElementById("con");
        var names = ["陈纪法","张三","李四","胡宝林","柏洪洋"];
        var flag = true;//保存当前停止状态
        var timer = null;
        oBtn.onclick = function () {
            if(flag){
                oBtn.innerHTML = "stop";
                timer = setInterval(function () {
                    // names中的值应该是[0,4]  [0,5)
                    oCon.innerHTML = names[Math.floor(Math.random()*names.length)];
                },30)
            }else{
                oBtn.innerHTML = "start";
                clearInterval(timer);
            }
 
            flag = !flag;
        }
    </script>
</body>
</html>